package com.itheima.jdbcdemo.controller;


import com.itheima.jdbcdemo.domain.Student;
import com.itheima.jdbcdemo.service.StudentService;
import com.itheima.jdbcdemo.service.StudentServiceImpl;
import org.junit.Test;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class StudentControllerImpl implements StudentController{
    StudentService service = new StudentServiceImpl();

    @Override
    @Test
    public void findAll() {
        ArrayList<Student> students = service.findAll();
        for (Student student : students) {
            System.out.println(student);
        }
    }

    @Override
    @Test
    public void findById() {
        Student student = service.findById(1);
        System.out.println(student);
    }

    @Override
    @Test
    public void insert() {
        /*SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = dateFormat.parse("2012-12-11");
        } catch (ParseException e) {
            e.printStackTrace();
        }*/
        Student student = new Student(null,"王三样",29,new Date());
        int insert = service.insert(student);
        if (insert>0){
            System.out.println("添加成功!");
        }else {
            System.out.println("添加失败!!!");
        }
    }

    @Override
    @Test
    public void update() {
        Student student = new Student(2,"王五",25,new Date());
        int update = service.update(student);
        if (update>0){
            System.out.println("修改成功!");
        }else {
            System.out.println("修改失败!");
        }
    }

    @Override
    @Test
    public void delete() {
        int delete = service.delete(6);
        if (delete>0){
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
    }
}
